主题
恢复中断的更新 - SoftUpdateTryRecover
函数简介
当 zip/rar 更新在提交阶段被中断(存在 update_in_progress.flag)时,尝试从 .ola_update\backup 将文件回滚到更新前状态。
返回结构与 SoftUpdateGetLastStatus 相同(Code / Phase / StatusCode / Detail 等)。回滚成功或无中断标志时通常 Code=1;回滚失败时 Code=0 并带失败详情。
接口名称
SoftUpdateTryRecoverDLL调用
long SoftUpdateTryRecover(string installRoot);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| installRoot | 字符串 | 安装根目录。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
OlaSoftUpdateLastStatusReturn status = ola.SoftUpdateTryRecover("C:\\App");
if (status.Code == 0) {
// 回滚失败:status.Message / status.Detail
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
OlaSoftUpdateLastStatusReturn status = ola.SoftUpdateTryRecover(@"C:\App");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
json_result = ola.SoftUpdateTryRecover(r"C:\App")
# Python SDK 返回 JSON 字符串,需自行解析java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.OlaSoftUpdateLastStatusReturn;
OLAPlugServer ola = new OLAPlugServer();
OlaSoftUpdateLastStatusReturn status = ola.SoftUpdateTryRecover("C:\\App");go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
status := ola.SoftUpdateTryRecover(`C:\App`)rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let status = ola.soft_update_try_recover(r"C:\App");cpp
var ola = com("OlaPlug.OlaSoft")
var status = ola.SoftUpdateTryRecover("C:\App")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
Set status = ola.SoftUpdateTryRecover("C:\App")text
.局部变量 ola, OLAPlug
.局部变量 status, OlaSoftUpdateLastStatusReturn
ola.创建 ()
status = ola.SoftUpdateTryRecover(“C:\App”)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var json = ola.SoftUpdateTryRecover("C:\\App");
// Aardio SDK 返回 JSON 字符串,需自行解析text
变量 ola <类型 = OLAPlugServer>
变量 status <类型 = OlaSoftUpdateLastStatusReturn>
ola = 新建 OLAPlugServer
status = ola.SoftUpdateTryRecover("C:\App")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
OlaSoftUpdateLastStatusReturn status = ola.SoftUpdateTryRecover("C:\\App");原生 DLL 调用
cpp
long ptr = SoftUpdateTryRecover("C:\\App");
if (ptr != 0) {
char buffer[2048] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long SoftUpdateTryRecover(string installRoot);
long ptr = SoftUpdateTryRecover(@"C:\App");
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string result = sb.ToString();
}python
from ctypes import CDLL, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ptr = ola.SoftUpdateTryRecover(b"C:\\App")
if ptr:
buf = create_string_buffer(2048)
ola.GetStringFromPtr(ptr, buf, 2048)
ola.FreeStringPtr(ptr)
result = buf.value.decode("utf-8")返回值
| 调用方式 | 返回值 | 说明 |
|---|---|---|
| SDK | OlaSoftUpdateLastStatusReturn | 与 SoftUpdateGetLastStatus 相同结构 |
| 原生 DLL | 非 0 | 成功,返回 JSON 字符串指针 |
| 原生 DLL | 0 | 调用失败 |
注意事项
| 项目 | 说明 |
|---|---|
| 适用范围 | 主要用于 zip/rar 覆盖流程;exe 安装器的回滚依赖安装器自身。 |
| backup 缺失 | 若 flag 存在但 backup 缺失,将返回失败状态(Code=0 / StatusCode=0),需人工介入。 |
| 自动恢复 | SoftUpdateStart 开始时也会尝试一次自动恢复。 |
| 释放内存 | 原生返回指针需 FreeStringPtr。 |
